package org.hxyjs.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Expert;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ExpertService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 expertController
//@RequestMapping("/expertController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /expertController
public class ExpertController {
	@Resource
    ExpertService expertService;

	@GetMapping("/experts")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Expert> getAllExpert() throws Exception{
    	System.out.println("查询全部专家");
    	return expertService.getAllExperts();
    }

	@PostMapping("/expert")
	@ResponseBody
	public DTO<Expert> addExpert(@RequestBody Expert expert) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加专家成功");
		return expertService.addExpert(expert);
	}
	@DeleteMapping("/expert/{eno}")
	@ResponseBody
    public DTO<Expert> deleteExpertByEno(@RequestBody @PathVariable("eno") String eno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(eno+"删除专家成功");
    	return expertService.deleteExpertByEno(eno);
    }

	@GetMapping("/expert/{eno}")
	@ResponseBody
	public DTO<Expert> getExpertByEno(@PathVariable("eno") String eno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(eno+"根据主键查询专家成功");
		return expertService.getExpertByEno(eno);
	}

	@PatchMapping("/expert")
	@ResponseBody
	public DTO<Expert> updateExpertByEno(@RequestBody Expert expert) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改专家成功");
		System.out.println(expert);
		return expertService.updateExpertByEno(expert);
	}

	@RequestMapping("/experts/pageInfo")
	@ResponseBody
	public DTO<Expert> getExpertByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return expertService.getExpertByPage(pageInfo);
	}

}
